<template>
  <el-dialog
    ref="content"
    :visible.sync="showDialog"
    :before-close="check"
    title="新增"
    width="75%"
  >
    <el-collapse v-model="activeNames">
      <el-collapse-item
        title="基本信息"
        name="1"
      >
        <!--     <el-card>
      <div slot="header">
        <span>基本信息</span>
      </div> -->
        <div class="basicInfo">
          <el-form :model="ruleForm" :rules="rules">
            <el-row type="flex" justify="start">
              <!-- <el-col :span="8">
              <el-form-item label="用户编号:">
                {{ userInfo.userNumber }}
              </el-form-item>
            </el-col> -->
              <el-col :span="8">
                <el-form-item label="用户状态:" prop="required" label-width="110px">
                  <el-select
                    v-model="ruleForm.userStatus"
                    :disabled="true"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      value="1"
                      label="待销售"
                    />
                    <el-option
                      value="2"
                      label="待激活"
                    />
                    <el-option
                      value="3"
                      label="激活"
                    />
                    <el-option
                      value="4"
                      label="待销户"
                    />
                    <el-option
                      value="5"
                      label="销户"
                    />
                    <el-option
                      value="6"
                      label="超期未激活"
                    />
                    <el-option
                      value="7"
                      label="服务过期"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="用户ID:" prop="userId" label-width="125px">
                  <el-input
                    v-model="ruleForm.userId"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="地域:" label-width="154px">
                  <el-select
                    v-model="ruleForm.userAreacode"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      v-for="item in userAreacodeArr"
                      :value="item.typeId"
                      :key="item.typeId"
                      :label="item.typeName"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row type="flex" justify="start">
              <el-col :span="8">
                <el-form-item label="用户类型:" prop="required" label-width="110px">
                  <el-select
                    v-model="ruleForm.userType"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      value="0"
                      label="其他"
                    />
                    <el-option
                      value="1"
                      label="公免用户"
                    />
                    <el-option
                      value="2"
                      label="认证黑名单"
                    />
                    <el-option
                      value="6"
                      label="商务用户"
                    />
                    <el-option
                      value="7"
                      label="测试用户"
                    />
                    <el-option
                      value="8"
                      label="集团大客户"
                    />
                    <el-option
                      value="9"
                      label="普通营业厅"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否冻结:" prop="required" label-width="125px">
                  <el-select
                    v-model="ruleForm.userFreezestatus"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      value="1"
                      label="是"
                    />
                    <el-option
                      value="2"
                      label="否"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="用户密码:" prop="userPassword" label-width="154px">
                  <el-input
                    v-model="ruleForm.userPassword"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <!-- <el-col :span="6">
              <el-form-item label="用户批次:">
                {{ userInfo.userFreezestatus }}
              </el-form-item>
            </el-col> -->
            </el-row>
            <el-row type="flex" justify="start">
              <el-col :span="8">
                <el-form-item label="用户来源:" label-width="110px">
                  <el-select
                    v-model="ruleForm.userComefrom"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      v-for="item in userComefromArr"
                      :value="item.typeId"
                      :label="item.typeName"
                      :key="item.typeId"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="8">
                <el-form-item label="注册时间:">
                  <el-date-picker
                    v-model="ruleForm.userCreatetime"
                    :picker-options="pickerOptions1"
                    :editable="false"
                    type="datetime"
                    size="mini"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择开始时间"
                    style="width: 50%"
                  />
                </el-form-item>
              </el-col> -->
              <el-col :span="8">
                <el-form-item label="账号有效期天数:" class="is-required" label-width="125px">
                  <el-input
                    v-model="ruleForm.userEffectivedays"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="运营商:" label-width="154px">
                  <el-select
                    v-model="ruleForm.userOperator"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      v-for="item in userOperatorArr"
                      :value="item.typeId"
                      :label="item.typeName"
                      :key="item.typeId"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="8">
                <el-form-item label="用户批次:">
                  <el-input
                    v-model="ruleForm.batchNumber"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col> -->
              <!-- <el-col :span="8">
              <el-form-item label="机顶盒编号:">
                {{ userInfo.userBoxmac }}
              </el-form-item>
            </el-col> -->
            </el-row>
            <el-row>
              <!-- <el-col :span="8">
                <el-form-item label="用户区域信息:" prop="required">
                  <el-select
                    v-model="ruleForm.userCity"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      value="1"
                      label="鞍山"
                    />
                    <el-option
                      value="2"
                      label="海城"
                    />
                    <el-option
                      value="3"
                      label="大连"
                    />
                    <el-option
                      value="4"
                      label="沈阳"
                    />
                  </el-select>
                </el-form-item>
              </el-col> -->
              <el-col :span="8" type="flex" justify="start">
                <el-form-item label="支付类型:" prop="required" label-width="110px">
                  <el-select
                    v-model="ruleForm.userPaytype"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      value="1"
                      label="预付费"
                    />
                    <el-option
                      value="0"
                      label="后付费"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="6">
              <el-form-item label="最后活动地址:">
                {{ userInfo.userPaytype }}
              </el-form-item>
            </el-col> -->
              <el-col :span="8">
                <el-form-item label="平台:" prop="required" label-width="125px">
                  <el-select
                    v-model="ruleForm.platformId"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      v-for="item in plat"
                      :key="item.typeId"
                      :value="item.typeId"
                      :label="item.typeName"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="超出有效期仍可激活:" prop="required" label-width="154px">
                  <el-select
                    v-model="ruleForm.userDelayactivation"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      value="1"
                      label="是"
                    />
                    <el-option
                      value="0"
                      label="否"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- <el-row>
              <el-col :span="8">
                <el-form-item label="运营商:" prop="required">
                  <el-select
                    v-model="ruleForm.userOperator"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      v-for="item in userOperatorArr"
                      :value="item.typeId"
                      :label="item.typeName"
                      :key="item.typeId"
                    />
                  </el-select>
                </el-form-item>
              </el-col> -->
            <!-- <el-col :span="8">
                <el-form-item label="激活时间:">
                  <el-date-picker
                    v-model="ruleForm.userActivatetime"
                    :picker-options="pickerOptions1"
                    :editable="false"
                    type="datetime"
                    size="mini"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择开始时间"
                    style="width: 50%"
                  />
                </el-form-item>
              </el-col> -->
            <!-- </el-row> -->
            <!-- <el-row> -->
            <!--  <el-col :span="8">
                <el-form-item label="受理方式:" prop="required">
                  <el-select
                    v-model="ruleForm.acceptWay"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      value="0"
                      label="其他"
                    />
                    <el-option
                      value="1"
                      label="公免用户"
                    />
                    <el-option
                      value="2"
                      label="黑名单"
                    />
                    <el-option
                      value="6"
                      label="商务用户"
                    />
                    <el-option
                      value="7"
                      label="测试用户"
                    />
                    <el-option
                      value="8"
                      label="集团大客户"
                    />
                    <el-option
                      value="9"
                      label="普通营业厅"
                    />
                  </el-select>
                </el-form-item>
              </el-col> -->
            <!-- <el-col :span="8">
              <el-form-item label="用户分组:">
                <el-select v-model="ruleForm.userInfo.userEpggroup" size="mini" style="width:80%">
                  <el-option value="0" label="其他" />
                  <el-option value="1" label="公免用户" />
                  <el-option value="2" label="黑名单" />
                  <el-option value="6" label="商务用户" />
                  <el-option value="7" label="测试用户" />
                  <el-option value="8" label="集团大客户" />
                  <el-option value="9" label="普通营业厅" />
                </el-select>
              </el-form-item>
            </el-col> -->
            <!-- </el-row> -->
            <el-row type="flex" justify="start">
              <el-col :span="23">
                <el-form-item label="账号有效期:" label-width="110px">
                  <el-date-picker
                    v-model="ruleForm.userLicensingwindowstart"
                    :editable="false"
                    :disabled="true"
                    type="datetime"
                    size="mini"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择开始时间"
                    style="width: 30%"
                  />
                  至
                  <el-date-picker
                    v-model="ruleForm.userLicensingwindowend"
                    :disabled="true"
                    :editable="false"
                    type="datetime"
                    size="mini"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择开始时间"
                    style="width: 30%"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="23">
                <el-form-item label="激活有效期:" class="is-required" label-width="110px">
                  <el-date-picker
                    v-model="ruleForm.userActivationeffectivestart"
                    :editable="false"
                    type="datetime"
                    size="mini"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss   "
                    placeholder="选择开始时间"
                    style="width: 30%"
                  />
                  <!-- <el-popover
                  v-if="userInfo.userLicensingwindowstart"
                  :content="userInfo.userActivationeffectivestart"
                  placement="top"
                  trigger="hover">
                  <span slot="reference" style="cursor:pointer" type="info">{{ userInfo.userActivationeffectivestart.length > 10 ? userInfo.userActivationeffectivestart.slice(0,10) + '...' : userInfo.userActivationeffectivestart }}</span>
                </el-popover> -->
                  至
                  <el-date-picker
                    v-model="ruleForm.userActivationeffectiveend"
                    :editable="false"
                    type="datetime"
                    size="mini"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss   "
                    placeholder="选择开始时间"
                    style="width: 30%"
                  />
                  <!-- <el-popover
                  v-if="userInfo.userLicensingwindowstart"
                  :content="userInfo.userActivationeffectiveend"
                  placement="top"
                  trigger="hover">
                  <span slot="reference" style="cursor:pointer" type="info">{{ userInfo.userActivationeffectiveend.length > 10 ? userInfo.userActivationeffectiveend.slice(0,10) + '...' : userInfo.userActivationeffectiveend }}</span>
                </el-popover> -->
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </el-collapse-item>
      <el-collapse-item
        title="设备信息"
        name="4"
      >
        <div class="basicInfo">
          <el-button
            type="primary"
            size="mini"
            round
            @click="addequ"
          >新增设备信息</el-button>
          <el-button
            type="primary"
            size="mini"
            round
            @click="editequ"
          >编辑设备信息</el-button>
          <el-table
            :data="deviceList"
            highlight-current-row
            border
            style="width: 100%;margin-top:15px"
          >
            <el-table-column label="设备MAC地址">
              <template slot-scope="{row, $index}">
                <span v-show="row.status">{{ row.deviceMacAddress }}</span>
                <el-input
                  v-show="!row.status"
                  v-model="deviceList[$index].deviceMacAddress"
                  style="width:80%"
                  size="mini"
                />
              </template>
            </el-table-column>
            <el-table-column label="设备编号">
              <template slot-scope="{row, $index}">
                <span v-show="row.status">{{ row.deviceID }}</span>
                <el-input
                  v-show="!row.status"
                  v-model="deviceList[$index].deviceID"
                  style="width:80%"
                  size="mini"
                />
              </template>
            </el-table-column>
            <el-table-column label="设备型号">
              <template slot-scope="{row, $index}">
                <span v-show="row.status">{{ row.deviceModel }}</span>
                <el-input
                  v-show="!row.status"
                  v-model="deviceList[$index].deviceModel"
                  style="width:80%"
                  size="mini"
                />
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="{row, $index}">
                <el-button
                  size="mini"
                  round
                  plain
                  type="danger"
                  @click="remove($index)"
                >
                  移除绑定
                </el-button>
                <el-button
                  size="mini"
                  round
                  plain
                  type="primary"
                  @click="saveMac($index, row.deviceMacAddress)"
                >
                  保存
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-collapse-item>
      <!-- </el-card> -->
      <el-collapse-item
        title="个人信息"
        name="2"
      >
        <!--     <el-card>
      <div slot="header">
        <span>个人信息</span>
      </div> -->
        <div class="basicInfo">
          <el-form>
            <el-row>
              <el-col :span="8">
                <el-form-item label="姓名:" label-width="110px">
                  <el-input
                    v-model="ruleForm.userName"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="昵称:" label-width="110px">
                  <el-input
                    v-model="ruleForm.userNickname"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="邮政编码:" label-width="100px">
                  <el-input
                    v-model="ruleForm.userZip"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <!-- <el-col :span="8">
              <el-form-item label="积分:">
                <el-input v-model="ruleForm.userInfo.userCreditTotal" size="mini" style="width:80%" />
              </el-form-item>
            </el-col> -->
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="性别:" label-width="110px">
                  <el-select
                    v-model="ruleForm.userGentle"
                    size="mini"
                    style="width:80%"
                  >
                    <el-option
                      value="1"
                      label="男"
                    />
                    <el-option
                      value="2"
                      label="女"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="身份证号:" label-width="110px">
                  <el-input
                    v-model="ruleForm.userIdentity"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="账户:" label-width="100px">
                  <el-input
                    v-model="ruleForm.userPortalid"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="出生日期:" label-width="110px">
                  <el-date-picker
                    v-model="ruleForm.userBirthday"
                    :picker-options="pickerOptions1"
                    :editable="false"
                    type="date"
                    size="mini"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择时间"
                    style="width: 80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="籍贯:" label-width="110px">
                  <el-input
                    v-model="ruleForm.userNativeplace"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="固定电话:" label-width="100px">
                  <el-input
                    v-model="ruleForm.userTelephone"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="手机号:" label-width="110px">
                  <el-input
                    v-model="ruleForm.userMobilephone"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="QQ:" label-width="110px">
                  <el-input
                    v-model="ruleForm.userQQ"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="邮箱:" label-width="100px">
                  <el-input
                    v-model="ruleForm.userEmail"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="密码提示问题:" label-width="110px">
                  <!-- <el-popover
                  v-if="userInfo.userQuestion"
                  :content="userInfo.userQuestion"
                  placement="top"
                  trigger="hover">
                  <span slot="reference" style="cursor:pointer" type="info">{{ userInfo.userQuestion.length > 10 ? userInfo.userQuestion.slice(0,10) + '...' : userInfo.userQuestion }}</span>
                </el-popover> -->
                  <el-input
                    v-model="ruleForm.userQuestion"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="密码找回问题:" label-width="110px">
                  <!-- <el-popover
                  v-if="userInfo.userAnswer"
                  :content="userInfo.userAnswer"
                  placement="top"
                  trigger="hover">
                  <span slot="reference" style="cursor:pointer" type="info">{{ userInfo.userAnswer.length > 10 ? userInfo.userAnswer.slice(0,10) + '...' : userInfo.userAnswer }}</span>
                </el-popover> -->
                  <el-input
                    v-model="ruleForm.userAnswer"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="紧急邮箱:" label-width="100px">
                  <el-input
                    v-model="ruleForm.userUrgent"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="所有终端:" label-width="110px">
                  <el-input
                    v-model="ruleForm.userTerminal"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="所在地:" label-width="110px">
                  <el-input
                    v-model="ruleForm.userRegion"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="IP地址:" label-width="100px">
                  <el-input
                    v-model="ruleForm.userLastactip"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="工作单位:" label-width="110px">
                  <!-- <el-popover
                  v-if="userInfo.userCompany"
                  :content="userInfo.userCompany"
                  placement="top"
                  trigger="hover">
                  <span slot="reference" style="cursor:pointer" type="info">{{ userInfo.userCompany.length > 10 ? userInfo.userCompany.slice(0,10) + '...' : userInfo.userCompany }}</span>
                </el-popover> -->
                  <el-input
                    v-model="ruleForm.userCompany"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="居住地址:" label-width="110px">
                  <!-- <el-popover
                  v-if="userInfo.userHomeadrress"
                  :content="userInfo.userHomeadrress"
                  placement="top"
                  trigger="hover">
                  <span slot="reference" style="cursor:pointer" type="info">{{ userInfo.userHomeadrress.length > 10 ? userInfo.userHomeadrress.slice(0,10) + '...' : userInfo.userHomeadrress }}</span>
                </el-popover> -->
                  <el-input
                    v-model="ruleForm.userHomeadrress"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="工作地址:" label-width="100px">
                  <!-- <el-popover
                  v-if="userInfo.userWorkadrress"
                  :content="userInfo.userWorkadrress"
                  placement="top"
                  trigger="hover">
                  <span slot="reference" style="cursor:pointer" type="info">{{ userInfo.userWorkadrress.length > 10 ? userInfo.userWorkadrress.slice(0,10) + '...' : userInfo.userWorkadrress }}</span>
                </el-popover> -->
                  <el-input
                    v-model="ruleForm.userWorkadrress"
                    size="mini"
                    style="width:80%"
                  />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <!-- </el-card> -->
      </el-collapse-item>
      <!-- <el-collapse-item
        title="会员积分"
        name="3"
      >
        <el-form label-position="left">
          <el-row>
            <el-col :span="8">
              <el-form-item label="总积分:">
                88888
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="总成长值:">
                55555
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="当前会员等级:">
                黄金会员
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-collapse-item> -->
    </el-collapse>
    <div class="btnArr">
      <el-button
        type="primary"
        size="small"
        style="width:7%"
        round
        @click="save"
      >
        保存
      </el-button>
      <el-button
        plain
        type="primary"
        size="mini"
        round
        style="width:7%"
        @click="check"
      >
        取消
      </el-button>
    </div>
  </el-dialog>
</template>
<script>
import secret from '@/utils/secret'
import { watch } from '@/api/liantong'
import { mapGetters } from 'vuex'
import { newSave, checkId, getSelect } from '@/api/search.js'
import { numAndWord, positive, user, checkMail, checkPhone } from '@/utils/validate.js'
export default {
  name: 'WatchInfo',
  props: {
    // 遮罩
    dialogAdd: {
      type: Boolean,
      default: false
    },
    platForm: {
      type: Array,
      default: () => []
    }
  },
  data() {
    const userIdRule = (rule, value, callback) => {
      console.log(value)
      console.log(rule)
      if (!numAndWord(value)) {
        callback(new Error('用户ID为字母、数字或字母数字组合'))
      } else {
        callback()
      }
    }
    const userIdPassword = (rule, value, callback) => {
      if (!numAndWord(value)) {
        callback(new Error('密码为字母、数字或字母数字组合'))
      } else {
        callback()
      }
    }
    return {
      userComefromArr: [],
      deviceList: [],
      activeNames: ['1'],
      showDialog: false,
      userAreacodeArr: [], // 区域数组
      ruleForm: {
        userFreezestatus: '2',
        userStatus: '2',
        deviceBeanList: [],
        userId: '',
        userType: '9',
        userPassword: '',
        userComefrom: '',
        userCreatetime: '',
        batchNumber: '',
        userCity: '',
        userPaytype: '0',
        platformId: '',
        userOperator: '',
        userActivatetime: '',
        userAreacode: '',
        acceptWay: '',
        userLastactip: '',
        userLicensingwindowstart: '',
        userLicensingwindowend: '',
        userEffectivedays: '365000',
        userActivationeffectivestart: '2000-01-01 00:00:00',
        userActivationeffectiveend: '2999-12-31 23:59:59',
        userDelayactivation: '0',
        groupId: '',
        packageId: '',
        userName: '',
        userNickname: '',
        userGentle: '',
        userIdentity: '',
        userPortalid: '',
        userBirthday: '',
        userNativeplace: '',
        userTelephone: '',
        userMobilephone: '',
        userQQ: '',
        userEmail: '',
        userQuestion: '',
        userAnswer: '',
        userUrgent: '',
        userTerminal: '',
        userRegion: '',
        userCompany: '',
        userHomeadrress: '',
        userWorkadrress: '',
        postalCode: '',
        fixedIP: '',
        IPAddress: '',
        permissions: ''
      },
      plat: [],
      userOperatorArr: [], // 运营商
      rules: {
        userId: [{
          required: true, validator: userIdRule, trigger: 'blur'
        }],
        required: [{
          required: true, trigger: 'blur', message: '必填项'
        }],
        userPassword: [{
          min: 3, message: '密码长度最少为3位', trigger: 'blur'
        }, {
          required: true, validator: userIdPassword, trigger: 'blur'
        }]
      },
      list: [],
      pickerOptions1: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        }
      },
      iddd: null
    }
  },
  computed: {
    ...mapGetters(['assignment', 'token']) // userInfo.userType
  },
  watch: {
    dialogAdd(newVal) {
      // console.log(newVal)
      this.showDialog = newVal
      this.plat = this.platForm
      if (newVal) {
        this.getSelects()
      }
      // this.getUser(this.id, this.plat)
      /* this.showDialog = newVal
      if (!this.$route.meta.platformId) {
        if (!this.plat) {
          if (!this.id) {
            this.getUser(this.idd, this.platformId)
          } else {
            this.getUser(this.id, this.platformId)
          }
        } else {
          this.getUser(this.id, this.plat)
        }
      } else {
        if (!this.id) {
          this.getUser(this.idd, this.platIdd)
        } else {
          this.getUser(this.id, this.platformId)
        }
      } */
    }
    // id(newVal) {
    //   // console.log(newVal)
    //   // 判断是分组还是查询
    //   if (!this.$route.meta.platformId) {
    //     if (!this.plat) {
    //       this.getUser(newVal, this.platformId)
    //     } else {
    //       this.getUser(newVal, this.plat)
    //     }
    //   }
    //   else {
    //     this.getUser(newVal, this.$route.meta.platformId)
    //   }
    // },
    // idd(newVal) {
    //   if (!this.$route.meta.platformId) {
    //     this.getUser(newVal, this.platIds)
    //   } else {
    //     this.getUser(newVal, this.$route.meta.platformId)
    //   }
    // }
  },
  mounted() {},
  methods: {
    addequ() {
      this.deviceList.push({
        deviceMacAddress: '',
        deviceID: '',
        deviceModel: '',
        status: false
      })
    },
    saveMac(index, content) {
      console.log(index)
      console.log(content)
      if (!content) {
        this.$message({
          type: 'error',
          message: 'mac地址为必填项'
        })
        return false
      }
      // this.deviceList[index] = true
      this.$set(this.deviceList[index], 'status', true)
    },
    editequ() {
      if (this.deviceList.length > 0) {
        this.deviceList.forEach(item => {
          item.status = false
        })
      }
      console.log(this.deviceList)
    },
    save() {
      console.log(this.ruleForm)
      var data = {
        userId: this.ruleForm.userId,
        platformId: this.ruleForm.platformId
      }
      if (!this.ruleForm.userId) {
        this.$message({
          type: 'error',
          message: '用户ID为必填项'
        })
        return false
      }
      if (!this.ruleForm.platformId) {
        this.$message({
          type: 'error',
          message: '平台为必填项'
        })
        return false
      }
      /* if (!this.ruleForm.userAreacode) {
        this.$message({
          type: 'error',
          message: '地域为必填项'
        })
        return false
      } */
      if (!numAndWord(this.ruleForm.userPassword)) {
        this.$message({
          type: 'error',
          message: '用户密码为字母、数字或字母加数字组合'
        })
        return false
      }
      // positive
      if (this.ruleForm.userEffectivedays && !positive(this.ruleForm.userEffectivedays)) {
        this.$message({
          type: 'error',
          message: '账号有效期天数必须为正整数'
        })
        return false
      }
      if (this.ruleForm.userIdentity && !user(this.ruleForm.userIdentity)) {
        this.$message({
          type: 'error',
          message: '身份证号输入有误'
        })
        return false
      }
      if (this.ruleForm.userMobilephone && !checkPhone(this.ruleForm.userMobilephone)) {
        this.$message({
          type: 'error',
          message: '手机号输入有误'
        })
        return false
      }
      if (this.ruleForm.userEmail && !checkMail(this.ruleForm.userEmail)) {
        this.$message({
          type: 'error',
          message: '邮箱输入有误'
        })
        return false
      }
      if (this.ruleForm.userUrgent && !checkMail(this.ruleForm.userUrgent)) {
        this.$message({
          type: 'error',
          message: '紧急邮箱输入有误'
        })
        return false
      }
      /* if (!this.ruleForm.userLicensingwindowstart || !this.ruleForm.userLicensingwindowend) {
        this.$message({
          type: 'error',
          message: '账号有效期为必填项'
        })
        return false
      } */
      if (!this.ruleForm.userActivationeffectivestart || !this.ruleForm.userActivationeffectiveend) {
        this.$message({
          type: 'error',
          message: '激活有效期为必填项'
        })
        return false
      }
      checkId(secret.Encrypt(data)).then(res => {
        if (res.resultCode === '0000') {
          /* if (!this.ruleForm.userAreacode) {
            this.$message({
              type: 'error',
              message: '地域为必填项'
            })
            return false
          } */
          if (!numAndWord(this.ruleForm.userPassword)) {
            this.$message({
              type: 'error',
              message: '用户密码为字母、数字或字母加数字组合'
            })
            return false
          }
          if (!this.ruleForm.userPassword) {
            this.$message({
              type: 'error',
              message: '地域为必填项'
            })
            return false
          }
          if (!this.ruleForm.platformId) {
            this.$message({
              type: 'error',
              message: '平台为必填项'
            })
            return false
          }
          /* if (!this.ruleForm.userLicensingwindowstart || !this.ruleForm.userLicensingwindowend) {
            this.$message({
              type: 'error',
              message: '账号有效期为必填项'
            })
            return false
          } */
          if (!this.ruleForm.userActivationeffectivestart || !this.ruleForm.userActivationeffectiveend) {
            this.$message({
              type: 'error',
              message: '激活有效期为必填项'
            })
            return false
          }
          this.ruleForm.deviceBeanList = this.deviceList
          newSave(secret.Encrypt(this.ruleForm)).then(res => {
            this.$message({
              message: '新增成功',
              type: 'success'
            })
            this.check(true)
          })
        } else {
          this.$message({
            type: 'error',
            message: res.resultDesc
          })
        }
      })
    },
    getSelects() {
      // 地域
      var data = {
        functionType: 'areaCode'
      }
      getSelect(secret.Encrypt(data)).then(res => {
        if (res.resultCode === '0000') {
          this.userAreacodeArr = res.data.list
        }
      })
      // 运营商
      var data1 = {
        functionType: 'userOperator'
      }
      getSelect(secret.Encrypt(data1)).then(res => {
        if (res.resultCode === '0000') {
          this.userOperatorArr = res.data.list
        }
      })
      // 用户来源
      var data2 = {
        functionType: 'userComefrom'
      }
      getSelect(secret.Encrypt(data2)).then(res => {
        if (res.resultCode === '0000') {
          this.userComefromArr = res.data.list
        }
      })
    },
    remove(index) {
      this.$confirm('确定要移除绑定吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deviceList.splice(index, 1)
        /* this.$message({
          type: 'success',
          message: '移除成功'
        }) */
      })
    },
    // 父子组件回调
    check(val) {
      this.showDialog = false
      this.$emit('closeDialog', val)
      this.deviceList = []
      this.activeNames = ['1']
      this.ruleForm = {
        userFreezestatus: '2',
        userStatus: '2',
        deviceBeanList: [],
        userId: '',
        userType: '9',
        userPassword: '',
        userComefrom: '',
        userCreatetime: '',
        batchNumber: '',
        userCity: '',
        userPaytype: '0',
        platformId: '',
        userOperator: '',
        userActivatetime: '',
        userAreacode: '',
        acceptWay: '',
        userLastactip: '',
        userLicensingwindowstart: '',
        userLicensingwindowend: '',
        userEffectivedays: '365000',
        userActivationeffectivestart: '2000-01-01 00:00:00',
        userActivationeffectiveend: '2999-12-31 23:59:59',
        userDelayactivation: '0',
        groupId: '',
        packageId: '',
        userName: '',
        userNickname: '',
        userGentle: '',
        userIdentity: '',
        userPortalid: '',
        userBirthday: '',
        userNativeplace: '',
        userTelephone: '',
        userMobilephone: '',
        userQQ: '',
        userEmail: '',
        userQuestion: '',
        userAnswer: '',
        userUrgent: '',
        userTerminal: '',
        userRegion: '',
        userCompany: '',
        userHomeadrress: '',
        userWorkadrress: '',
        postalCode: '',
        fixedIP: '',
        IPAddress: '',
        permissions: ''
      }
    },
    clickss(e) {
      e.scrollTop = 0
    },
    // 请求列表
    getUser(id, platformId) {
      const res = {
        // token: this.token,
        userId: id,
        platformId: platformId
      }
      console.log('请求参数')
      console.log(res)
      if (this.dislogEdit) {
        watch(secret.Encrypt(res)).then(response => {
          var data = response.data
          console.log('返回数据')
          console.log(data)
          this.userInfo = data
        })
      }
    }
  }
}
</script>
<style scoped>
.el-col{
  margin-bottom: 7px !important;
}
</style>

<style>
.el-dialog {
  margin-top: 10vh !important;
  max-height: calc(100% - 120px);
}
.el-dialog {
  display: flex;
  flex-direction: column;
}
.el-dialog .el-dialog__body {
  overflow: auto;
}
.basicInfo {
  width: 99%;
  margin: 0 auto;
  padding-left: 20px;
}
.required::before {
  content: '*';
  display: inline-block;
  color: #f56c6c;
  margin-right: 4px;
}
.btnArr {
  display: flex;
  justify-content: flex-end;
  margin-top: 25px;
  margin-bottom: 5px;
}
</style>
